//
//  HELModifyPwdVC.m
//  HandheldELearn
//
//  Created by 陈武琦 on 16/7/13.
//  Copyright © 2016年 陈武琦. All rights reserved.
//

#import "HELModifyPwdVC.h"
#import "NSString+Utilities.h"
@interface HELModifyPwdVC ()
@property (weak, nonatomic) IBOutlet UITextField *currentPwd;
@property (weak, nonatomic) IBOutlet UITextField *pwdNew;
@property (weak, nonatomic) IBOutlet UITextField *pwdSure;
@property (weak, nonatomic) IBOutlet UIButton *commitBtn;

@end

@implementation HELModifyPwdVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.commitBtn.layer.borderWidth = .5;
    self.commitBtn.layer.borderColor = kBtnColor.CGColor;
    self.commitBtn.layer.cornerRadius = 5;
    [self titleView:@"修改密码"];
    // Do any additional setup after loading the view from its nib.
}
- (IBAction)commit:(id)sender {
    if ([self.currentPwd.text isEmpty]) {
        alertMessage(@"请输入当前密码");
        return;
    }
    if ([self.pwdNew.text isEmpty]) {
        alertMessage(@"请输入新密码");
        return;
    }
    if ([self.pwdSure.text isEmpty]) {
        alertMessage(@"请确认密码");
        return;
    }
    if (![self.pwdNew.text isEqualToString:self.pwdSure.text]) {
        alertMessage(@"两次密码不一致");
        return;
    }
    
    HELUserInfoM *userInfo = [HELAppManager userInfo];
    if (!userInfo.userId) {
        alertMessage(@"用户id获取失败");
        return;
    }
    
    cwqHud(self.view);
    weakSelf_define;
    //    oldPwd  旧密码
    //
    //    newPwd 新密码
    //
    //    userId 用户ID
    NSDictionary *param = @{@"newPwd":self.pwdNew.text, @"oldPwd":self.currentPwd.text, @"userId":userInfo.userId};
    [[HELNetworkManager sharedMg] POST:helModifyUrl parameters:param success:^(id responseObject) {
        if (responseObject[@"exception"]) {
            cwqHudRequestError(responseObject[@"exception"]);
        }else {
            
            cwqHudSuccess(hud);
            alertMessage(@"修改成功");
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }
        
    } failure:^(NSString *err) {
        cwqHudRequestError(err);
    }];
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    [self.view endEditing:YES];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
